package tech.aistar.day02;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 本类功能:
 *
 * @author cxylk
 * @date 2020/9/16 18:52
 */
@WebServlet(urlPatterns = "/day02/session/to")
public class SessionToAction extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.从session作用域中获取数据，根据key来获取

        //第二次遇到req.getSession,并不会再次重复创建session空间
        HttpSession session=req.getSession();
        PrintWriter out=resp.getWriter();
        out.println(session.getAttribute("uname"));
    }
}
